#include "Executorlmpl.hpp"

#include <memory>

#include "CmderFactory.hpp"
#include "Singleton.hpp"

namespace adas
{
Executor* Executor::NewExecutor(const Pose& pose,CarsType carType) noexcept
{
    return new (std::nothrow) Executorlmpl(pose,carType);
}

Executorlmpl::Executorlmpl(const Pose& pose,CarsType carType) noexcept : poseHandler(pose,carType)
{
}

Pose Executorlmpl::Query() const noexcept
{
    return poseHandler.Query();
}

void Executorlmpl::Execute(const std::string& commands) noexcept
{
    const auto cmders = Singleton<CmderFactory>::Instance().GetCmders(commands);
    std::for_each(cmders.begin(), cmders.end(),
                  [this](const Cmder& cmder) noexcept { cmder(poseHandler).DoOperate(poseHandler); });
}

}  // namespace adas